package argo.hot100.tree;

public class DiameterOfBinaryTree {

    int res = 0;

    public int diameterOfBinaryTree(TreeNode root) {
        if (root == null) {
            return 0;
        }
        treeDepth(root);
        return res;

    }


    public int treeDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int l = treeDepth(root.left);
        int r = treeDepth(root.right);
        res = Math.max(res, l + r);
        return Math.max(l, r) + 1;
    }


}
